﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.UI;

public class ToggleDeviceView : MonoBehaviour
{
    public ToggleDevice Device;

    public Toggle ToggleBtn;
    public Button BtnClear;

    public Text LabelName;
    public Text LabelStatus;

    void Start()
    {
        Assert.IsNotNull(Device);
        LabelName.text = Device.Name;
        Binding();
    }

    void Update()
    {
        UpdateView();
    }

    void Binding()
    {
        BtnClear.onClick.AddListener(() => {
            Device.Clear();
        });

        ToggleBtn.onValueChanged.AddListener((v) => {
            Device.Value = v;
        });
    }

    void UpdateView()
    {
        ToggleBtn.SetIsOnWithoutNotify(Device.Value);
        LabelStatus.text = Device.IsPressed ? "已按下" : "未按下";
    }
}
